#pragma once

#include "nlohmann/json.hpp"

namespace Protocol {
class RequestDevListMsgObject {
    std::size_t tick;
    std::size_t time;
    std::string src;
    struct List {
        std::size_t offset;
        std::size_t count;
        std::vector<std::string> type;

        List(const std::string &t)
            : offset(0), count(128), type({t}) {}

        friend void to_json(nlohmann::json &j, const List &l) {
            j = {{"offset", l.offset}, {"count", l.count}};
            for (const auto &s : l.type) {
                j["type"].emplace_back(s);
            }
        }
    } list;

public:
    RequestDevListMsgObject(const std::string &type = "DLT698")
        : tick(1),
          time(std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::system_clock::now().time_since_epoch()).count()),
          src("dev_dlt698"),
          list(type) {
    }

    friend void to_json(nlohmann::json &j, const RequestDevListMsgObject &r) {
        j = {
            {"tick", r.tick},
            {"time", r.time},
            {"src", r.src},
            {"list", r.list},
        };
    }
};

};  // namespace Protocol
